<?php
/**********************************************************
** Lime Manager
** Thomas Knobloch & Clément Troesch
** Administrator BDD Ajax View
***********************************************************/
?>

<?php include_once "../../model/AdministratorModel.php"; ?>
<?php include_once "../../model/SessionModel.php"; ?>
<?php session_start(); ?>


<div class="section_title" id="bdd"><h1> Stockage </h1></div>
<div class="section_info">
	Obtention des renseignements relatifs au stockage de la base de données(tablespaces, fichiers, ...) 
</div>

<div class="article">

<?php
if(isset($_SESSION['session']->userLogin)){
?>
<div class="section_title_small_blue"><h4>Tablespaces</h4></div>

	<div class="tableContainer">
		<table class="tableQueryCenter">
			<tr>
				<th>Tablespace</th>
				<th>Pourcentage</th>
				<th>Utilisé(en Mo)</th>
				<th>Aloué(en Mo)</th>
				<th>Status</th>
			</tr>
		<?php

		$nbrow = AdministratorModel::getStockageInfos($_SESSION['session']->currentConnection, $result);
		
			if($_SESSION['session']->currentConnection->type == "MYSQL"){

				foreach ($result as $row) {
				echo "<tr>";
				echo "<td>".$row['TABLESPACE_NAME']."</td>\n";
				echo "<td><progress value=\"".number_format((($row['DATA_LENGTH']*100)/$row['MAX_DATA_LENGTH']),2)."\" max=\"100\"></progress>".number_format((($row['DATA_LENGTH']*100)/$row['MAX_DATA_LENGTH']),2)."%</td>\n";
				echo "<td>".($row['DATA_LENGTH']/1048576)."</td>\n";
				echo "<td>".($row['MAX_DATA_LENGTH']/1048576)."</td>\n";
				echo "<td>".$row['STATUS']."</td>\n";
				echo"</tr>";
				}
			
			}
			else if($_SESSION['session']->currentConnection->type == "ORACLE"){
				
				foreach ($result as $row) {
				echo "<tr>";
				echo "<td>".$row['TABLESPACE_NAME']."</td>\n";
				echo "<td><progress value=\"".number_format((($row['BYTES']*100)/$row['MAXBYTES']),2)."\" max=\"100\"></progress>".number_format((($row['BYTES']*100)/$row['MAXBYTES']),2)."%</td>\n";
				echo "<td>".($row['BYTES']/1048576)."</td>\n";
				echo "<td>".($row['MAXBYTES']/1048576)."</td>\n";
				echo "<td>".$row['STATUS']."</td>\n";
				echo"</tr>";
				}
			}
		?>
		
		</table>
	</div>

	
	<div class="tableContainer" >
		<table class="tableQueryCenter">
			<tr>
			<?php
				if($_SESSION['session']->currentConnection->type == "MYSQL"){
			?>
				<th>Nom de fichier</th>
				<th>Tablespace</th>
				<th>Taille d'extension</th>
				<th>Taille initiale</th>
				<th>Taille maximum</th>
				<th>Taille d'extension auto.</th>
				<th>Date de création</th>
				<th>Dernière mise à jour</th>
				<th>Dernière consultation</th>
			<?php
			}
			else if($_SESSION['session']->currentConnection->type == "ORACLE"){
			?>
				<th>Nom de fichier</th>
				<th>Tablespace</th>
				<th>Blocs</th>
				<th>Blocs maximums</th>
				<th>Auto-extensible</th>
				<th>Incrément de</th>
				<th>Données utilisateurs</th>
				<th>Blocs utilisables</th>
				
			<?php
			}
			?>
			</tr>
		<?php
		$nbrow = AdministratorModel::getMemoryInfos($_SESSION['session']->currentConnection, $result);
		
		if($_SESSION['session']->currentConnection->type == "MYSQL"){
			foreach ($result as $row) {
				echo "<tr>";
				echo "<td>".$row['FILE_NAME']."</td>\n";
				echo "<td>".$row['TABLESPACE_NAME']."</td>\n";
				echo "<td>".$row['EXTENT_SIZE']."</td>\n";
				echo "<td>".$row['INITIAL_SIZE']."</td>\n";
				echo "<td>".$row['MAXIMUM_SIZE']."</td>\n";
				echo "<td>".$row['AUTOEXTEND_SIZE']."</td>\n";
				echo "<td>".$row['CREATION_TIME']."</td>\n";
				echo "<td>".$row['LAST_UPDATE_TIME']."</td>\n";
				echo "<td>".$row['LAST_ACCESS_TIME']."</td>\n";
				echo "<td>".$row['DATA_FREE']."</td>\n";
				echo"</tr>";
			}
		}
		else if($_SESSION['session']->currentConnection->type == "ORACLE"){
			foreach ($result as $row) {
				echo "<tr>";
				echo "<td>".$row['FILE_NAME']."</td>\n";
				echo "<td>".$row['TABLESPACE_NAME']."</td>\n";
				echo "<td>".$row['BLOCKS']."</td>\n";
				echo "<td>".$row['MAXBLOCKS']."</td>\n";
				echo "<td>".$row['AUTOEXTENSIBLE']."</td>\n";
				echo "<td>".$row['INCREMENT_BY']."</td>\n";
				echo "<td>".$row['USER_BYTES']."</td>\n";
				echo "<td>".$row['USER_BLOCKS']."</td>\n";
				echo"</tr>";
			}
		}
	}
		?>
		</table>
	</div>
</div>